1 <?php
2
3 session_start();

4
5 if
(isset($_POST['submit'])) {
6     
7     include
'dbh.inc.php';
8
9     $uid = mysqli_real_escape_string($conn, $_POST[
'uid']);
10     $pwd = mysqli_real_escape_string($conn, $_POST[
'pwd']);
11
12     
//Error handlers
13     
//Check if inputs are empty
14     
if (empty($uid) || empty($pwd)) {
15         header(
"Location: ../index1.php?login=empty");
16         $_SESSION[
'errors'] = array("Your username or password was incorrect.");
17         exit();
18     }
else {
19         $sql =
"SELECT * FROM users WHERE uname='$uid' OR email='$uid'";
20         $result = mysqli_query($conn, $sql);
21         $resultCheck = mysqli_num_rows($result);
22         
if ($resultCheck < 1) {
23             $_SESSION[
'errors'] = array("Your username or password was incorrect.");
24             header(
"Location: ../index1.php?login=error");
25             exit();
26         }
else {
27             
if ($row = mysqli_fetch_assoc($result)) {
28                 
//De-hashing the password
29                 $hashedPwdCheck = password_verify($pwd, $row[
'pwd']);
30                 
if ($hashedPwdCheck == false) {
31                     $_SESSION[
'errors'] = array("Your username or password was incorrect.");
32                     header(
"Location: ../index1.php?login=error");
33                     exit();
34                 } elseif ($hashedPwdCheck ==
true) {
35                     
//Log in the user here
36                     $_SESSION[
'u_id'] = $row['id'];
37                     $_SESSION[
'u_first'] = $row['fname'];
38                     $_SESSION[
'u_last'] = $row['lname'];
39                     $_SESSION[
'age'] = $row['age'];
40                     $_SESSION[
'phone'] = $row['phone'];
41                     $_SESSION[
'u_email'] = $row['email'];
42                     $_SESSION[
'u_uid'] = $row['uname'];
43                     header(
"Location: ../second.php?login=success");
44                     exit();
45                 }
46             }
47         }
48     }
49 }
else {
50     header(
"Location: ../index1.php?login=error");
51     $_SESSION[
'errors'] = array("Your username or password was incorrect.");
52     exit();
53 }


Gõ tìm kiếm nhanh...